package config

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func InitSql() {
	dbuser := beego.AppConfig.String("dbuser")
	dbpass := beego.AppConfig.String("dbpass")
	dbhost := beego.AppConfig.String("dbhost")
	dbname := beego.AppConfig.String("dbname")
	dbport, err := beego.AppConfig.Int("dbport")
	if nil != err {
		dbport = 3306
	}

	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", dbuser, dbpass, dbhost, dbport, dbname))
}
